# Maintainer: Jan Alexander Steffens (heftig) <heftig@archlinux.org>
# Maintainer: Jan de Groot <jgc@archlinux.org>
# Contributor: Andre Klitzing <aklitzing () online () de>

pkgname=libytnef
pkgver=1.9.3
pkgrel=1
epoch=1
pkgdesc="Yerase's TNEF Stream Reader library (decodes winmail.dat)"
url="https://github.com/Yeraze/ytnef"
license=(GPL)
arch=(x86_64)
depends=(glibc)
makedepends=(perl git)
optdepends=('perl: ytnefprocess')
_commit=d9b2f01d125c9b178f7a00ec397cc2a9f258e8e1  # tags/v1.9.3
source=("git+https://github.com/Yeraze/ytnef#commit=$_commit")
sha256sums=('SKIP')

pkgver() {
  cd ytnef
  git describe --tags | sed 's/^v//;s/-/+/g'
}

prepare() {
  cd ytnef

  # https://github.com/Yeraze/ytnef/pull/74
  git cherry-pick -n f7ff4f66a1e6f8a9936aea2add6512c4b23a4261

  # CVE-2021-3404
  # https://bugs.archlinux.org/task/70056
  git cherry-pick -n f9ff4a203b8c155d51a208cadadb62f224fba715

  # CVE-2021-3403
  # https://bugs.archlinux.org/task/70056
  git cherry-pick -n f2380a53fb84d370eaf6e6c3473062c54c57fac7

  ./autogen.sh
}

build() {
  cd ytnef
  ./configure --prefix=/usr --disable-static
  make
}

package() {
  cd ytnef
  make DESTDIR="$pkgdir" install
}
